package cn.kgc.wyttest.service.impl;

import cn.kgc.wyttest.domain.ServiceAppoint;
import cn.kgc.wyttest.dto.ReturnResult;
import cn.kgc.wyttest.dto.ServiceAppointOutPutDto;
import cn.kgc.wyttest.mapper.ServiceAppointMapper;
import cn.kgc.wyttest.service.ServiceAppointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;

/**
 * @author Chang
 * @program: wytTest
 * @description: 服务预约信息impl
 * @date 2022-10-17 07:26:25
 */
@Service
public class ServiceAppointServiceImpl implements ServiceAppointService {

    @Autowired
    private ServiceAppointMapper serviceAppointMapper;


    @Override
    public ServiceAppointOutPutDto selectByNumber(String number) {

        List<ServiceAppoint> serviceAppoints = serviceAppointMapper.selectServiceAppointListByNumber(number);

        System.out.println(serviceAppoints);

        try {
            if (serviceAppoints!=null){
                for (ServiceAppoint serviceAppoint:serviceAppoints){
                    //服务名称
                    String serviceName = serviceAppoint.getServiceName();
                    //门店名称
                    String shopName = serviceAppoint.getShopName();
                    //核销截至时间
                    Date verificationEndTime = serviceAppoint.getVerificationEndTime();
                    //服务价格
                    String servicePrice = serviceAppoint.getServicePrice();
                    //购买时间
                    Date orderTime = serviceAppoint.getOrderTime();
                    //核销状态
                    Integer verificationStatus = serviceAppoint.getVerificationStatus();
                    ServiceAppointOutPutDto serviceAppointOutPutDto = new ServiceAppointOutPutDto();
                    cn.kgc.wyttest.dto.Service service = new cn.kgc.wyttest.dto.Service();
                    service.setServiceName(serviceName);
                    service.setShopName(shopName);
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    service.setVerificationEndTime(simpleDateFormat.format(verificationEndTime));
                    service.setServicePrice(servicePrice);
                    service.setOrderTime(simpleDateFormat.format(orderTime));
                    service.setVerificationStatus(String.valueOf(verificationStatus));
                    ReturnResult returnResult = new ReturnResult();
                    returnResult.setStatus("0000");
                    returnResult.setMsg("查询成功！");
                    returnResult.setData(service);
                    serviceAppointOutPutDto.setReturnResult(returnResult);
                    return serviceAppointOutPutDto;
                }
            }else {
                ServiceAppointOutPutDto serviceAppointOutPutDto = new ServiceAppointOutPutDto();
                ReturnResult returnResult = new ReturnResult();
                returnResult.setStatus("0001");
                returnResult.setMsg("团购券对应的服务订单不存在！");
                returnResult.setData(null);
                serviceAppointOutPutDto.setReturnResult(returnResult);
                return serviceAppointOutPutDto;
            }

        }catch (Exception e){
            e.printStackTrace();
        }

        return null;
    }
}
